package com.youdoneed.community.forum.service;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.youdoneed.base.application.AppException;
import com.youdoneed.community.common.utils.StringUUIdUtil;
import com.youdoneed.community.forum.dao.ForumreportreasonMapper;
import com.youdoneed.community.forum.entity.Forumreportreason;

@Service
public class ForumreportreasonService {
    private final Logger logger = LoggerFactory.getLogger(ForumcommentService.class);

    @Autowired
    ForumreportreasonMapper forumreportreasonMapper;

    @Transactional
    public int deleteForumReportReasonById(String id) {
        try {
            return forumreportreasonMapper.deleteByPrimaryKey(id);
        } catch (Exception e) {
            logger.error("根据ID删除失败!");
            return 0;
        }
    }

    @Transactional
    public int saveForumReportReason(Forumreportreason forumreportreason) {
        if (null == forumreportreason) {
            logger.info("forumreportreason参数为空!");
            throw new AppException("forumreportreason参数不能为空");
        }

        try {
            forumreportreason.setForumReportReasonId(StringUUIdUtil.getUUID());
            forumreportreason.setCreateDate(new Date());
            return forumreportreasonMapper.insert(forumreportreason);

        } catch (Exception e) {
            logger.error("保存举报原因异常：" + e);
            return 0;
        }
    }

    @Transactional
    public Forumreportreason selectForumReportReasonById(String id) {
        if (!StringUtils.hasText(id)) {
            throw new AppException("id参数不能为空！");
        }
        try {
            return forumreportreasonMapper.selectByPrimaryKey(id);

        } catch (Exception e) {
            logger.error("查询举报原因异常：" + e);
            return null;
        }
    }

    @Transactional
    public int updateForumReportReason(Forumreportreason forumreportreason) {
        if (null == forumreportreason) {
            throw new AppException("forumreportreason参数不能为空！");
        }
        try {
            return forumreportreasonMapper.updateByPrimaryKeySelective(forumreportreason);

        } catch (Exception e) {
            logger.error("查询举报原因异常：" + e);
            return 0;
        }
    }

    @Transactional
    public List<Forumreportreason> selectOnLineReportReason() {
        try {
            return forumreportreasonMapper.selectOnLineReportReason();
        } catch (Exception e) {
            logger.error("查询举报原因异常：" + e);
            return null;
        }
    }
}
